package com.revert.service;

/**
 * @Description:
 */
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@Service
public class RedisService {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;




    // 设置数据
    public void set(String key, Object value) {
        redisTemplate.opsForValue().set(key, value);
    }

    // 设置数据并设置过期时间
    public void setWithExpireTime(String key, Object value, long expireTime, TimeUnit timeUnit) {
        redisTemplate.opsForValue().set(key, value, expireTime, timeUnit);
    }

    // 获取数据
    public Object get(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public void delete(Object key){
        redisTemplate.delete(key+"");
    }
}
